package com.zyt.service.Impl;

import com.zyt.mapper.ClazzMapper;
import com.zyt.mapper.EmpMapper;
import com.zyt.mapper.StudentMapper;
import com.zyt.pojo.JobOption;
import com.zyt.pojo.Student;
import com.zyt.pojo.clazzOption;
import com.zyt.service.ReportService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {


    @Override
    public List<Map> countStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }

    @Override
    public clazzOption countStudentCountData() {
        List<Map<String, Object>> list = studentMapper.countStudentCountData();
        if(!CollectionUtils.isEmpty(list)){
            List<Object> clazzList = list.stream().map(map -> {
                return map.get("cname");
            }).toList();

            List<Object> dataList = list.stream().map(map -> {
                return map.get("scount");
            }).toList();

            return new clazzOption(clazzList, dataList);
        }
        return null;
    }


    @Override
    public List<Map<String, Object>> getGenderData() {
        List<Map<String, Object>> list = empMapper.countEmpGenderData();
        return list;
    }

    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public JobOption getEmpJobData() {
        //1.调用mapper接口,获取职位数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();

        //2.组装结果,返回
        List<Object> JobList = list.stream().map(dataMap -> dataMap.get(("pos"))).toList();
        List<Object> DataList = list.stream().map(dataMap -> dataMap.get(("num"))).toList();
        return new JobOption(JobList, DataList);
    }
}

